<template>
  <div style="padding: 10px">

    <!--    搜索区-->
    <div style="margin: 10px 0px">
      <el-input v-model="search" placeholder="请输入开箱密码" style="width: 15%" clearable></el-input>
      <el-button type="primary" style="margin-left: 5px" @click="load">搜索</el-button>
    </div>

    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="oid" label="id"  sortable />
      <el-table-column prop="time" label="日期"  />
      <el-table-column prop="cabId" label="存储柜编号"  />
      <el-table-column prop="boxId" label="存储箱编号" />
      <el-table-column prop="cost" label="费用" />
      <el-table-column prop="openPw" label="开箱密码" />
      <el-table-column prop="uid" label="uid" />
      <el-table-column prop="finished" label="物品是否被取走" >
        <template #default="scope">
          <span v-if="scope.row.finished === 1"> 是</span>
          <span v-if="scope.row.finished === 0"> 否</span>
        </template>
      </el-table-column>
    </el-table>

    <div style="margin: 10px 0">
      <el-pagination
          v-model:currentPage="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[5, 10, 20, 50,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>

import request from "../utils/request";

export default {
  name: 'History',
  components: {
  },
  data() {
    return{
      search:"",
      total:"",
      currentPage:1,
      pageSize:10,
      tableData:[],
      tempData:[],
      user:"",
      uid:"",
      rightPage:"",
      tempTotal:"",
    }
  },

  methods:{
    load(){
      request.get("/history",{
        params:{
          pageNum : this.currentPage,
          pageSize: this.pageSize,
          search:this.search,
          uid: this.uid
        }
      }).then(res =>{
        if (this.search !== null){
          this.pageNum = 1
        }
        console.log(res.data)
        this.tableData = res.data.data.records
        this.total = res.data.data.total
      })
    },
    handleDelete(id){
      console.log(id)
      request.delete("/orderings/" + id).then(res =>{
        if (res.data.code === '0') {
          this.$message({
            type: "success",
            message: "删除成功！"
          })
          this.load();
        } else {
          this.$message({
            type: "error",
            message: res.data.msg
          })
        }
      })
    },
    // 改变当前每页的个数触发
    handleSizeChange(pageSize){
      this.pageSize = pageSize
      this.load()
    },
    // 改变当前页码触发
    handleCurrentChange(currentPage){
      this.currentPage = currentPage
      this.load()
    },
  },
  created() {
    let userStr = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(userStr)
    this.uid = this.user.id
    this.load()
  }
}
</script>
